#!/bin/bash

#scp -B -q -i ../.ssh/private_rsa_2048 remote/mailq.sh nagios@192.168.2.100:/tmp/mailq.sh
#ssh -o ControlPath=/usr/local/nagios/nagssh/var/%r@%h:%p.sock 128.0.0.5 cscript.exe //nologo  check_memory_percentage_space_used.vbs -h localhost -inst _TOTAL -t 80,90


export > /tmp/varrssh.log
#export NAGIOS__HOSTSSH_UPLOADDIR='~'
#export NAGIOS_HOSTADDRESS='128.0.0.5'
#export NAGIOS__HOSTSSH_SOCKET='/usr/local/nagios/nagssh/var/%r@%h:%p.sock'

#export NAGIOS__SERVICESSH_SCRIPT='/dev/null'

REPOSITORY=/usr/local/nagios/nagssh/libexec/remote

SCRIPT=$1
shift

# master channel ouvert ?
msg=`ssh -o ControlPath=$NAGIOS__HOSTSSH_SOCKET -O check $NAGIOS_HOSTADDRESS 2>&1`
ret=$?
msg=`echo $msg|tr '\n' ' '`

if [ $ret -eq 255 ]
then
    echo "UNKNOWN - Could not access SSH master socket : $msg"
    exit 3
fi

scp -q -B -o ControlPath=$NAGIOS__HOSTSSH_SOCKET $REPOSITORY/$SCRIPT.class $NAGIOS_HOSTADDRESS:$SCRIPT.class && \
/usr/local/nagios/libexec/check_by_ssh -o ControlPath=$NAGIOS__HOSTSSH_SOCKET -H $NAGIOS_HOSTADDRESS -C "java $SCRIPT $*"

#ssh -q -o ControlPath=$NAGIOS__HOSTSSH_SOCKET $NAGIOS_HOSTADDRESS "cscript.exe //nologo //T:60 $SCRIPT $*"
#echo Toto
